use crate::{bootstrap::AppState, router::resp::RespVO, service};
use axum::{
    body::Body,
    extract::{Path, Query, State},
    http::Response,
    response::IntoResponse,
};
use sky_pojo::{dto, entities::setmeal::Model, vo::dish::DishItemVO};

pub async fn list_category_id(
    State(state): State<AppState>,
    Query(query): Query<dto::category::ListCategoryId>,
) -> Response<Body> {
    match service::setmeal::list(state.db_pool, query.category_id).await {
        Ok(vec) => RespVO::<Vec<Model>>::success("success".to_owned(), Some(vec)).into_response(),
        Err(e) => RespVO::<()>::error_without_data(e).into_response(),
    }
}

pub async fn dish_list(State(state): State<AppState>, Path(id): Path<i64>) -> Response<Body> {
    let res = service::setmeal::get_dish_item_by_id(state.db_pool, id)
        .await
        .map_err(|e| RespVO::<()>::error_without_data(e.to_string()).into_response())
        .unwrap();

    RespVO::<Vec<DishItemVO>>::success("success".to_owned(), Some(res)).into_response()
}
